Understanding Exchange on Solana: A Guide to Minting CPMM Pools
When creating a Centralized Money Market (CPMM) pool on Solana using the mintA and mintB fields in the createPool cpmm method, you may notice that your minted tokens are swapped when they should be identical. This phenomenon is known as token swapping.
In this article, we will dive deeper into why mintage A is being swapped for B instead of B for A, and provide a step-by-step solution to resolve this issue.
The createPool cpmm Method
The createPool cpmm method allows you to create a CPMM pool on Solana. It takes three parameters: the base token (A), its token (B), and an optional quote token (C). The method returns a Pool object, which contains information about the created pool.
pub fn createPool(
cpmmConfig: PoolConfig,
) -> Pool {
// Create a new CPMM pool with the specified parameters
}
Token Swap

When you call the createPool cpmm method, Solana uses the token swap algorithm to create a valid pool. This algorithm takes into account several factors, including:
- Token Names: The base token (A), its token (B), and quote tokens (C) must match in name.
- Token Decimals
: A and B have the same decimal places.
- Token Supply: The total amount of tokens must be equal.
When you create a mintA field with the desired values, Solana automatically generates a corresponding mintB field that represents its token. However, if these fields are swapped (e.g. mintB becomes mintA), the token swap algorithm will not produce the expected result.
Why is mint B being swapped?
There are several reasons why mint B might be swapped with mint A:
- Token mismatch: If
mintBandmintAhave different names, the token swap algorithm will swap them.
- Token decimals: Solana requires that
mintAandmintBhave the same decimal places. If they do not match, the token swap algorithm will swap them as well.
Token swap resolution
To resolve this issue, you need to ensure that mintA and mintB are generated correctly when creating a CPMM pool using the createPool cpmm method. Here is an updated example:
use solana_program::{
account_info::{next_account_info, AccountInfo},
entrypoint::ProgramResult,
program_error::PrintError,
pubkey::Pubkey,
};
pub fn createPool(
cpmmConfig: PoolConfig,
) -> ProgramResult {
let mintA = next_account_info("mint_A")?;
let mintB = next_account_info("mint_B")?;
// Create a new CPMM pool with the specified parameters
self.pool.create(cpmmConfig)?;
}
// Usage example:
fn main() {
let config = PoolConfig::new();
let result = createPool(config).unwrap();
println!("Created Pool: {:?}", result);
}
In this example, we generate mintA and mintB using the next_account_info function. We then pass these values to the createPool method.
By following these steps, you should be able to create a CPMM pool on Solana with identical mint tokens (A and B). If you are still having trouble, feel free to provide more details about your project, and I will do my best to assist you further.